﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Windows.Threading;
using System.Diagnostics;

namespace ManyTalk
{
    public partial class MainPage : UserControl
    {
        //全局计时器
        private DispatcherTimer timer = new DispatcherTimer();
        //确认在线计时器
        private DispatcherTimer onLiveTimer = new DispatcherTimer();

        public MainPage()
        {
            InitializeComponent();
			
			//初始化全屏
            Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
			
            //确认在线时间间隔为5秒
            onLiveTimer.Interval = new TimeSpan(0,0,5);
            onLiveTimer.Tick += new EventHandler(UserOnLive);
            onLiveTimer.Start();

            //设置计时器时间间隔为200毫秒
            timer.Interval = new TimeSpan(0,0,0,0,200);
            //为计时器添加处理器
            //timer.Tick += new EventHandler(timer_Tick);
            //计时器开始
            timer.Start();
        }

        void Content_FullScreenChanged(object sender, EventArgs e)
        {
            Content contentObject = Application.Current.Host.Content;
            if (contentObject.IsFullScreen)
            {
                FullScreenTextBlock.Text = "取消全屏";
            }
            else
            {
                FullScreenTextBlock.Text = "全屏模式";
            }
        }

        //每过5秒向服务器发送确认消息
        void UserOnLive(object sender, EventArgs e)
        {
            Debug.WriteLine("客户端向服务器发送在线消息。");
        }

        private void FullScreen_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			Content contentObject =Application.Current.Host.Content;
			contentObject.IsFullScreen = !contentObject.IsFullScreen;
			if(contentObject.IsFullScreen)
			{
				FullScreenTextBlock.Text = "取消全屏";
			}else
			{
				FullScreenTextBlock.Text = "全屏模式";	
			}
        }

        //计时器处理函数示例
        /*
        void timer_Tick(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }*/

    }
}
